package com.cloud.code.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * 最长回文串
 */
public class Demo4 {

    public static void main(String[] args) {
        int bbb = lengthOfLongestSubstring("wwkw");
        System.out.println(bbb);
    }

    public static int lengthOfLongestSubstring(String s) {
        int left = 0;
        int right = 0;

        int max = 0;
        Map<Character,Integer> map = new HashMap<>();
        while (right < s.length()) {
            char c = s.charAt(right++);
            map.put(c,map.getOrDefault(c,0)+1);

            while (map.get(c) > 1){
                left ++;
                map.put(c,map.getOrDefault(c,0)-1);
            }

            max = Math.max(max, right - left);
        }
        return max;
    }
}
